<!-- 物流公司审核 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="公司名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入公司名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="companyList">
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['tws:company:query']"
          >查看</el-button>
          <el-button
            style="color: #67c23a;"
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="handlePass(scope.row)"
            v-hasPermi="['tws:company:edit']"
          >通过</el-button>
          <el-button
            style="color: red;"
            size="mini"
            type="text"
            icon="el-icon-close"
            @click="handleFail(scope.row)"
            v-hasPermi="['tws:company:edit']"
          >驳回</el-button>
        </template>
      </el-table-column>
      <el-table-column label="公司名称" align="center" prop="companyName" />
      <el-table-column label="纳税人识别码" align="center" prop="taxNo" />
      <el-table-column label="道路运输经营许可证号" align="center" prop="licenseNo" />
      <el-table-column label="公司电话" align="center" prop="tel" />
      <el-table-column label="注册地址" align="center" prop="address" show-overflow-tooltip />
      <el-table-column label="法人" align="center" prop="legal" />
      <el-table-column label="联系人" align="center" prop="linker" />
      <el-table-column label="联系人电话" align="center" prop="linktel" />
      <el-table-column label="认证状态" align="center" prop="isCert" :formatter="isCertFormat" />
      <el-table-column label="状态" align="center" width="140" >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.state"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="1"
            inactive-value="2"
            active-text="正常"
            inactive-text="禁用" disabled>
          </el-switch>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />

    <!-- 添加或修改物流公司对话框 -->
    <el-dialog title="物流公司详情" :visible.sync="open" width="1000px" append-to-body :close-on-click-modal="false" @close="close">
      <company-form mode="3" :companyId="companyId" @close="close" />
    </el-dialog>

  </div>
</template>

<script>
import { listCompany, cert } from "@/api/tws/company";
import CompanyForm from '@/components/CompanyForm/index';

export default {
  name: "CompanyCert",
  components: {
    CompanyForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 是否显示弹出层
      open: false,
      // 总条数
      total: 0,
      companyId: null,
      // 物流公司表格数据
      companyList: [],
      // 认证状态字典
      isCertOptions: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        companyName: null,
        shortCode: null,
        taxNo: null,
        licenseNo: null,
        tel: null,
        address: null,
        legal: null,
        legaltel: null,
        linker: null,
        linktel: null,
        bank: null,
        bankcard: null,
        businessLicense: null,
        roadLicense: null,
        idCardImg1: null,
        idCardImg2: null,
        isCert: null,
        state: null,
        tenantId: null
      }
    };
  },
  created() {
    this.queryParams.isCert = this.$store.state.constants.isCert_shz; // 只查询审核中的
    this.getDict();
    this.getList();
  },
  methods: {
    /** 查询字典 */
    getDict() {
      // 认证状态字典
      this.getDicts("is_cert").then(response => {
        this.isCertOptions = response.data;
      });
    },
    /** 查询物流公司列表 */
    getList() {
      this.loading = true;
      listCompany(this.queryParams).then(response => {
        this.companyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 认证状态字典翻译
    isCertFormat(row, column) {
      return this.selectDictLabel(this.isCertOptions, row.isCert);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查看按钮操作 */
    handleView(row) {
      const id = row.id;
      this.open = true;
      this.companyId = null;
      setTimeout(() => {
        this.companyId = id;
      })
    },
    close() {
      this.open = false;
      this.getList();
    },
    /** 审核通过 */
    handlePass(row) {
      let that = this;
      that.$confirm('是否确认审核通过 "' + row.companyName + '" ?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let obj = {
          id: row.id,
          isCert: that.$store.state.constants.isCert_yrz
        }
        return cert(obj);
      }).then(() => {
        that.$modal.msgSuccess("审核成功");
        that.getList();
      }).catch(err => {
        that.getList();
      })
    },
    /** 审核不通过 */
    handleFail(row) {
      let that = this;
      that.$prompt('确认驳回 "' + row.companyName + '" 的申请,请输入原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputType: 'textarea',
        inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
        inputErrorMessage: '请输入原因'
      }).then(({ value }) => {
        let obj = {
          id: row.id,
          isCert: that.$store.state.constants.isCert_rzsb,
          failReason: value
        }
        return cert(obj);
      }).then(() => {
        that.$modal.msgSuccess("已驳回");
        that.getList();
      }).catch(() => {
        that.getList();
      })
    }
  }
};
</script>
